package org.dromara.crawler.controller;

import lombok.RequiredArgsConstructor;
import lombok.extern.slf4j.Slf4j;
import org.dromara.common.core.domain.R;
import org.dromara.crawler.mongo.mongodomain.EventNews;
import org.dromara.crawler.mongo.mongodomain.SemanticExtraction;
import org.dromara.crawler.mongo.mongoservice.CNNService;
import org.dromara.crawler.mongo.mongoservice.EventNewsService;
import org.dromara.crawler.mongo.mongoservice.SemanticExtractionService;
import org.dromara.crawler.mongo.mongoservice.XinHuaNetService;
import org.springframework.web.bind.annotation.*;

import java.util.List;


/**
 * 语义抽取接口控制类
 */

@Slf4j
@RequiredArgsConstructor
@RestController
@RequestMapping("/semanticExtraction")
public class SemanticExtractionController {

    private final SemanticExtractionService semanticExtractionService;

    private final XinHuaNetService xinHuaNetService;

    private final CNNService cnnService;

    private final EventNewsService eventNewsService;

    /**
     * 数据查询
     */
    @GetMapping("/getList")
    public R<List<SemanticExtraction>> getList(String eventName) {

        return R.ok(semanticExtractionService.getAll(eventName));
    }


    /**
     * 语义要素抽取结果录入
     */
    @PostMapping("/addSemantic")
    public R<Boolean> addSemantic(@RequestBody SemanticExtraction semanticExtraction) {
        try {
            return R.ok(semanticExtractionService.save(semanticExtraction));
        } catch (Exception e) {
            log.error("插入失败，原因：" + e.getMessage());
            return R.fail(e.getMessage());
        }
    }

    /**
     * 语义要素抽取结果查询
     */
    @GetMapping("/getEventNewsById")
    public R<List<EventNews>> getEventNewsById(String id) {

        try {
            return R.ok(eventNewsService.queryById(id));
        } catch (Exception e) {
            log.error("查询失败，原因：" + e.getMessage());
            return R.fail(e.getMessage());
        }

    }

    /**
     * 语义要素抽取获取所有
     */
    @GetMapping("/getAllEventNews")
    public R<List<EventNews>> getAllEventNews() {
        try {
            return R.ok(eventNewsService.queryAll());
        } catch (Exception e) {
            log.error("获取失败，原因：" + e.getMessage());
            return R.fail(e.getMessage());
        }
    }


}
